package com.kingland.zf.service;

import com.kingland.zf.mapper.UserModelMapper;
import com.kingland.zf.model.UserModel;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;


@Service
public class UserServiceImpl implements UserService{
    private UserModelMapper userModelMapper;
    private PasswordEncoder passwordEncoder;


    public UserServiceImpl(UserModelMapper userModelMapper,PasswordEncoder passwordEncoder) {
        this.userModelMapper = userModelMapper;
        this.passwordEncoder=passwordEncoder;
    }

    @Override
    public UserModel addUser(UserModel userModel) {
        userModel.setPassword ( this.passwordEncoder.encode(userModel.getPassword ()));
        this.userModelMapper.insert ( userModel );
        return userModel;
    }
}
